﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'userAdd')
	BEGIN
		DROP  Procedure  userAdd
	END
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[userAdd] 
	-- Add the parameters for the stored procedure here
	@user_first_name VARCHAR(50),
	@user_last_name VARCHAR(50),
	@user_name VARCHAR(50),
	@user_pwd VARCHAR(50),
	@app_id INT
AS	
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF EXISTS(	SELECT lit_usuario_id 
				FROM lit_usuario 
				WHERE lit_usuario_username = @user_name 
				AND lit_aplicacion_id = @app_id )
	BEGIN
		SELECT 0;
	END
    ELSE BEGIN
		INSERT INTO lit_usuario (lit_usuario_username, lit_usuario_password, lit_usuario_nombre, lit_usuario_apellido, lit_aplicacion_id)
		VALUES (@user_name, @user_pwd, @user_first_name, @user_last_name, @app_id)
		SELECT @@Identity;
	END
END
GO